package work;

/**
 * @TODO
 * @Author xu
 * 2025/2/24
 */import java.util.Random;
import java.util.Scanner;
public class Day4_9 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入班级总组数:");
        int groupCount = scanner.nextInt();
        System.out.print("请输入班级中每组的人数:");
        int studentsPerGroup = scanner.nextInt();

        int[][] scores = new int[groupCount][studentsPerGroup];
        Random random = new Random();

        int totalFail = 0;
        int totalSum = 0;
        int[] groupFails = new int[groupCount];
        int[] groupAverages = new int[groupCount];
        for (int i = 0; i < groupCount; i++) {
            int groupSum = 0;
            int groupFail = 0;
            for (int j = 0; j < studentsPerGroup; j++) {
                int score = random.nextInt(101);
                scores[i][j] = score;
                groupSum += score;
                if (score < 60) groupFail++;
            }
            totalSum += groupSum;
            totalFail += groupFail;
            groupFails[i] = groupFail;
            groupAverages[i] = (int) Math.round((double) groupSum / studentsPerGroup);
        }

        int maxGroupAvg = 0;
        for (int avg : groupAverages) {
            if (avg > maxGroupAvg) maxGroupAvg = avg;
        }

        int totalStudents = groupCount * studentsPerGroup;
        int classAverage = (int) Math.round((double) totalSum / totalStudents);
        for (int i = 0; i < groupCount; i++) {
            System.out.printf("第%d组不及格人数为: %d 人\n", i + 1, groupFails[i]);
            System.out.printf("第%d组平均分为: %d\n", i + 1, groupAverages[i]);
        }
        System.out.println("班级中单组最高平均分为:" + maxGroupAvg);
        System.out.println("班级中不及格人数为: " + totalFail + " 人");
        System.out.println("班级总平均分为: " + classAverage);
    }



}
